import 'package:flutter/material.dart';
import 'package:flutterdemo/pages/Detile/ListTitle.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++; // 右下角加号 +1
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.lightGreen,
        title: Text("demo2"),
        centerTitle: true,
      ),

      // ✅ 抽屉菜单
      drawer: Drawer(
        backgroundColor: Colors.lightBlue.shade100,
        child: ListView(
          padding: EdgeInsets.zero,
          children: <Widget>[
            const DrawerHeader(
              decoration: BoxDecoration(color: Colors.blue),
              child: Text(
                '抽屉头部',
                style: TextStyle(color: Colors.white, fontSize: 24),
              ),
            ),
            ListTile(
              leading: const Icon(Icons.home),
              title: const Text('首页'),
              onTap: () {
                Navigator.pop(context); // 关闭抽屉
                print("点击了首页");
              },
            ),
            ListTile(
              leading: const Icon(Icons.settings),
              title: const Text('设置'),
              onTap: () {
                Navigator.pop(context);
                print("点击了设置");
              },
            ),
            ListTile(
              leading: const Icon(Icons.message),
              title: const Text('消息'),
              onTap: () {
                Navigator.pop(context); // 关闭抽屉
                Navigator.push(
                  context,
                  MaterialPageRoute(builder: (context) => const ListTitle()),
                );
              },
            ),
          ],
        ),
      ),

      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                setState(() {
                  _counter += 8; // 中间按钮增加 8
                });
              },
              child: const Text('增加 8'),
            ),
            const SizedBox(height: 10),
            ElevatedButton(
              onPressed: () {
                setState(() {
                  _counter = 0; // 中间按钮重置
                });
              },
              child: const Text('重置计数器'),
            ),
            const Demo6(),
            const List1(),
          ],
        ),
      ),

      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter, // 右下角加号 +1
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}



// 这只是个组件
class Demo6 extends StatelessWidget {
  const Demo6({super.key});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Center(child: Image.asset("img/2222.jpg"));
  }
}

// 垂直列表-title
class List1 extends StatelessWidget {
  const List1({super.key});

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: ListView(
        children: const <Widget>[
          ListTile(title: Text("标题1")),
          ListTile(title: Text("标题2")),
          ListTile(title: Text("标题3")),
          ListTile(title: Text("标题4")),
          ListTile(title: Text("标题5")),
        ],
      ),
    );
  }
}
